#include<bits/stdc++.h>
using namespace std;
const long long mx=1e5+5,mx1=1e6+5;
long long d[mx],v[mx],a[mx],p[mx1];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        long long n,m,L,V,cnt=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++) cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++) cin>>p[i];
        for(int i=1;i<=n;i++)
        {
            if(v[i]<=V) continue;
            if(p[m]>=d[i]) cnt++;
        }
        cout<<cnt<<" ";
        if(cnt==0) cout<<m<<endl;
        else cout<<m-1<<endl;
    }
    return 0;
}
